<template lang="jade">
div#app
  loading(:show="show_loading", :text="正在读取数据...")

  div.top.homebanner
    div.warning 市场有风险,投资需谨慎
    swiper(:list="bannerlist", :aspect-ratio="300/750", :auto="true")

  div.homenotice
    i.iconfont &#xe7ab;
    ul(:style="topc")
      li(v-for="(index, item) in notice")
        a(v-link="{ name: 'newsDetail', params: { newsId: item.id } }") {{{item.title}}}
    span.message(v-link="{ path: '/message'}" )
      i.iconfont.mail &#xe705;
    i.ball(v-show=" message_new==1 ")
  div.hl
    ul
      li
        a(v-link="{ path: '/aboutus'}"  )
          i
            img(src="../assets/images/index/hl_icon_1.png")
          span 关于我们
      li
        a(@click="goAna()")
          i
            img(src="../assets/images/index/hl_icon_2.png")
          span 数据披露

      li
        a(v-link="{ path: '/promotion'}"  )
          i
            img(src="../assets/images/index/hl_icon_3.png")
          span 新手福利

      li
        a(v-link="{ path: '/faqs'}"  )
          i
            img(src="../assets/images/index/hl_icon_4.png")
          span 帮助中心



  div.sp_box(v-show=" novicelist!=false ")
    div.title 新手专享
    ul.productlist
      li(v-link="{ name: 'detail', params: { detailId: novicelist.borrow_name_no_type == '1' ? novicelist.name_no:novicelist.borrow_nid } }")
        div.title
          span.name {{novicelist.name}}
          span.fr 起投金额:100元
        flexbox
          flexbox-item(:span="4")
            span 借款金额
            b.mtxt {{novicelist.account}}元
          flexbox-item
            span 约定收益率
            b.af {{novicelist.borrow_apr}}%
          flexbox-item
            span 借款期限
            b {{novicelist.borrow_period}}个月

          flexbox-item
            a.p_btn_nob.tcenter {{getType('1', novicelist.status)}}

        flexbox
          flexbox-item(:span="6")
            剩余可投金额:{{novicelist.borrow_account_wait}}元
          flexbox-item
            progress(:percent="novicelist.borrow_account_scale", :show-cancel="false")
          flexbox-item(:span="2")
            span.mtxt {{novicelist.borrow_account_scale}}%

  div.sp_box
    div.title 推荐项目
      span.more(v-link="{ path: '/invest/index'}")
        更多>>
    ul.productlist
      li(v-for=" (index, item) in borrowlist | limitBy 2 " , @click ="goList(item)"  )

        div.title
          span.name{{item.name}}
          span.fr 起投金额:100元
        flexbox
          flexbox-item(:span="4")
            span 借款金额
            b.mtxt {{item.account}}元
          flexbox-item
            span 约定收益率
            b.af {{item.borrow_apr}}%
          flexbox-item
            span 借款期限
            b {{item.borrow_period}}个月
          flexbox-item

            a(v-if=" item.rel_time!='' &&  item.status == 1 ", class=" b_btn_nob min ") {{item.rel_time}}
            a(v-else, v-bind:class=" getType('2', item.status) ") {{getType('1', item.status)}}

        flexbox
          flexbox-item(:span="6")
            剩余可投金额:{{item.borrow_account_wait}}元
          flexbox-item
            progress(:percent="item.borrow_account_scale", :show-cancel="false")
          flexbox-item(:span="2")
            span.mtxt {{item.borrow_account_scale}}%

  div.sp_box
    div.title 房利宝
      span.more(v-link="{ path: '/invest/index?productype=group'}")
        更多>>
    ul.productlist
      li(v-for=" (index, item) in largelist  | limitBy 2 " , v-link="{ name: 'group', params: { groupId: item.name_no } }")
        div.title
          span.name{{item.name}}
          span.fr 起投金额:50万元
        flexbox
          flexbox-item(:span="4")
            span 借款金额
            b.mtxt {{item.account}}元
          flexbox-item
            span 约定收益率
            b.af {{item.borrow_apr}}%
          flexbox-item
            span 借款期限
            b {{item.borrow_period}}个月
          flexbox-item
            a.p_btn_nob.tcenter {{item.status_str}}

        flexbox
          flexbox-item(:span="6")
            剩余可投金额:{{item.pick}}元
          flexbox-item
            progress(:percent="item.percentage", :show-cancel="false")
          flexbox-item(:span="2")
            span.mtxt {{item.percentage}}%




  div.sc_box
    div.title
      span
        i.iconfont &#xe631;
        资讯频道
      span.more(v-link="{ path: '/news/index'}")
        更多>>
    ul.imglist
      li(v-for=" (index, item) in zixunlist ", v-link="{ name: 'newsDetail', params: { newsId: item.id } }" )
        div.img
          img(src="{{item.img_cover}}")
        div.info
          div.stitle {{item.title}}
          div.extra
            span {{item.insert_time}}
            span.fr
              i.iconfont &#xe63f;
              b {{item.click}}

  div.sc_box
    div.title
      span
        i.iconfont &#xe634;
        最新公告
      span.more(v-link="{ path: '/news/183'}")
        更多>>
    ul.newslist
      li(v-for=" (index, item) in gonggaolist ", v-link="{ name: 'newsDetail', params: { newsId: item.id } }" )
        span.name {{item.title}}
        span.fr {{item.insert_time}}



  div.sc_box
    div.title
      span
        i.iconfont &#xe641;
        网贷学堂
      span.more(v-link="{ path: '/news/195'}")
        更多>>
    ul.newslist
      li(v-for=" (index, item) in xuetanglist " , v-link="{ name: 'newsDetail', params: { newsId: item.id } }" )
        a
          span.name {{item.title}}
          span.fr {{item.insert_time}}

  footer
    //div.fmenu
      ul.triple
        li 关于有喜
        li 帮助中心
        li.none 登录注册
        li 安全保障
        li 信息披露
        li.none 联系我们
    div.copyright 深圳市有喜资产管理有限公司 版权所有 <br> 备案号：粤ICP备16008329号 <br>地址:广东省深圳市福田区车公庙创新科技广场一期B座1508C <br>座机：0755-83167199 手机：18617068080 <br>投资交流群：479966413

      ul.authority
        li
          a(href="https://ss.knet.cn/verifyseal.dll?sn=e16032944030062941tbic000000&ct=df&a=1&pa=0.01922142133116722", target="_blank")
            img(src="../assets/images/news/authority/cnnic.png")
        li
          a(href="http://webscan.360.cn/index/checkwebsite/url/www.uximoney.com", target="_blank")
            img(src="../assets/images/news/authority/360cert.png")
        li
          a(href="https://szcert.ebs.org.cn/207cbdb7-7b66-4332-aa5a-c7c9a656eabb", target="_blank")
            img(src="../assets/images/news/authority/govIcon.gif")
        li
          a(href="https://trustsealinfo.websecurity.norton.com/splash?form_file=fdf%2Fsplash.fdf&sap=&dn=www.uximoney.com&zoneoff=&lang=zh_CN", target="_blank")
            img(src="../assets/images/news/authority/norton.png")


</template>


<style>
@import '~vux/dist/vux.css';
</style>

<script>
var myNotice;
//import CssCircle from '../v-circle/components/css-circle.vue'
import {c_api_index} from '../config/api'
import '../assets/sass/common/circle.scss'
import '../assets/sass/index/index.scss'
import {Loading, Progress, Swiper, Flexbox, FlexboxItem} from 'vux'
//import IndexPage from '../components/index/index'
//import LoanPage from '../components/index/loan'
//import UserPage from '../components/index/user'

export default {

  //输入子类电话
  //props:['phone'],
  data () {
  	return{
  		currentView: 'index',
  		busy:false,
      percent2:25,
      showLogo:true,
      borrowlist:[],
      zixunlist:[],
      gonggaolist:[],
      xuetanglist:[],
      novicelist:false,
      notice:[],
      largelist:[],
      show_loading:true,
      activeIndex:0,
      message_new:0,
      activeStr:'',
      bannerlist: [{
        url: 'http://mp.weixin.qq.com/s?__biz=MzAxNjU0MDYxMg==&ampmid=400385458&ampidx=1&ampsn=78f6b8d99715384bdcc7746596d88359&ampscene=19#wechat_redirect',
        img: 'http://www.uximoney.com/data/upfiles/images/banner/banner_1489038237.jpg'
      }, {
        url: 'http://mp.weixin.qq.com/s?__biz=MzAxNjU0MDYxMg==&ampmid=400160890&ampidx=1&ampsn=29ef02af25793a11a3f6aec92bfb46c1&ampscene=19#wechat_redirect',
        img: 'http://www.uximoney.com/data/upfiles/images/banner/banner_1488337791.jpg'
      }, {
        url: 'http://mp.weixin.qq.com/s?__biz=MzAxNjU0MDYxMg==&ampmid=400094682&ampidx=1&ampsn=8231a2053b772b2108784fccc254d28c&ampscene=19#wechat_redirect',
        img: 'http://www.uximoney.com/data/upfiles/images/banner/banner_1488350227.jpg'
      }]

  	}
  },



  computed:{
    topc(){
      console.log('topc');
      return 'top:' + ( - this.activeIndex * 1 ) + 'rem';
    }
  },

  components: {
    Progress,
    Swiper,
    Flexbox,
    FlexboxItem,
    Loading
  },

  /*ready() {
    var that = this;
    setInterval(function() {
      if(that.activeIndex < that.notice.length-1) {
        that.activeIndex += 1;
      } else {
        that.activeIndex = 0;
      }
    }, 3000);
  },*/

  methods:{
    goList(ob){
      if(ob.borrow_name_no_type=="1"){
        this.$route.router.go('/invest/index?productype=current&listId='+ob.name_no)
      }else{
        this.$route.router.go('/invest/detail/'+ob.borrow_nid)
      }
    },
    moveUp(){

        /*$(obj).find("ul").animate({
            marginTop: "-45px"
        }, 500, function () {
            $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
        });*/



    },
    goAna(){
      this.$store.dispatch('setShowLoading', true);
      this.$route.router.go('/analysis')
    },
  	setView(key){
  		this.currentView = key;

      //localStorage.setItem("menu", this.currentView);

      if(key == 'user')
        this.showLogo = false;
      else
        this.showLogo = true;
  	},

    getType(type, val){

      var txt = "", cs = "";
      switch(val){
        case 1:
          txt = "预告"
          cs = "b_btn_nob tcenter"
          break;
        case 2:
          txt = "结清"
          cs = "p_btn_nob tcenter"
          break;
        case 3:
          txt = "还款中"
          cs = "p_btn_nob tcenter"
          break;
        case 4:
          txt = "投标中"
          cs = "p_btn_nob tcenter"
          break;
        case 5:
          txt = "查看"
          cs = "p_btn_nob tcenter"
          break;
      }
      return type == "1" ? txt:cs
    },
    getOrderType(val){
      var txt = ""
      switch(val){
        case "1":
          txt = "楼贷标"
          break;
        case "2":
          txt = "车贷标"
          break;
      }
      return txt
    },
    fetch: function () {
      var that = this;
      this.$http({url: c_api_index, method: 'GET', timeout:5000}).then(function (response) {
        /*this.banlance = response.data.banlance;
        this.items = this.items.concat(response.data.data);
        this.obj = Object.assign([], this.obj.concat(response.data.data));
        this.busy = false;*/

        this.bannerlist = response.data.data.bannerlist;
        //this.novicelist = [];
        this.novicelist = response.data.data.novicelist;
        this.largelist = response.data.data.largelist;
        this.borrowlist = response.data.data.borrowlist;
        this.zixunlist = response.data.data.zixunlist;
        this.gonggaolist = response.data.data.gonggaolist;
        this.xuetanglist = response.data.data.xuetanglist;
        this.notice = response.data.data.notice;
        this.message_new = response.data.message_new;
        //console.log(this.novicelist);
        this.$store.dispatch('setShowLoading', false);



        setInterval(function() {
          if(that.activeIndex < that.notice.length-1) {
            that.activeIndex += 1;
          } else {
            that.activeIndex = 0;
          }
        }, 3000);

        //next();
      }, function (res) {
          //console.log(res.status)
          //console.log(res.statusText)
          this.fetch();
      });
    }
  },
  route: {
    activate ( transition ) {
      this.$store.dispatch('setShowLoading', true);
      //更改父类电话
      //console.log(this.$router)
      var dphone = sessionStorage.getItem("login") == null ? '':localStorage.getItem("tel")

      this.$store.dispatch('setPhone', dphone);

      transition.next();
      this.fetch();
    }
  }
}
</script>
